import type { VxeTableGridOptions } from '@vben/plugins/vxe-table';

import type { OnActionClickFn } from '#/adapter/vxe-table';
import type { StepExecutionModel } from '#/api/production/models';

import { usPassResultOptions } from '#/api/production/models';

/**
 * 获取表格列配置。
 * @param onActionClick 表格操作按钮点击事件
 */
export function useColumns(
  onActionClick?: OnActionClickFn<StepExecutionModel>,
): VxeTableGridOptions<StepExecutionModel>['columns'] {
  return [
    { type: 'seq', width: 60 },
    { field: 'sn', title: '零件码', minWidth: 160 },
    { field: 'lineCode', title: '产线编号', width: 120 },
    { field: 'operationCode', title: '工序', width: 100 },
    { field: 'workstationCode', title: '工位', width: 100 },
    {
      field: 'passResult',
      title: '过站状态',
      width: 100,
      cellRender: {
        name: 'CellTag',
        options: usPassResultOptions(),
      },
    },
    { field: 'inboundTime', title: '进站时间', width: 150 },
    { field: 'outboundTime', title: '出站时间', width: 150 },
    { field: 'cycleTime', title: '用时(s)', width: 100 },
    {
      cellRender: {
        attrs: {
          onClick: onActionClick,
        },
        name: 'CellOperation',
        options: [{ code: 'open', text: '详情' }],
      },
      field: 'operation',
      fixed: 'right',
      title: '过程数据',
      width: 100,
    },
  ];
}
